#include "Node.h"
#include "Operator.h"

Node::Node(void)
{
}


Node::~Node(void)
{
}

Node* Node::parent() const
{
	return _parent;
}

unsigned int Node::countChildren() const
{
	return this->children.size();
}

vector<Node*> Node::getChildren() const
{
	return this->children;
}

Node* Node::getChild(unsigned int index) const
{
	if(index >= this->children.size())
	{
		return NULL;
	}
	else
	{
		return this->children[index];
	}
}

void Node::addChild(Node* child)
{
	if(child != NULL)
	{
		this->children.push_back(child);
	}
}

void Node::delChild(unsigned int index)
{
	if(index < this->children.size())
	{
		this->children.erase(this->children.begin()+index);
	}
}

void Node::delChild(Node* child)
{
	for(unsigned int i=0;i<this->children.size();i++)
	{
		if(this->children[i] == child)
		{
			this->children.erase(this->children.begin()+i);
			return;
		}
	}
}

void Node::delAllChildren()
{
	for(unsigned int i=0;i<this->children.size();i++)
	{
		this->children[i]->clear();
	}
	this->children.clear();
}

void Node::clear()
{
	for(unsigned int i=0;i<this->children.size();i++)
	{
		this->children[i]->clear();
	}
	delete this;
}

std::string Node::getName() const
{
	return this->_name;
}

void Node::setParent(Node* parent)
{
	this->_parent = parent;
}

unsigned int Node::getPriority() const
{
	return this->_priority;
}